﻿Namespace Controle

    Public Class YCDropDownList
        Inherits DropDownList
        Private pMsgNenhum As String = "Coloque sua mensagem"
        Private pTipo As EnumTipo = EnumTipo.Normal

        Public Enum EnumTipo
            Normal
            Mes
        End Enum

        Public Property Tipo() As EnumTipo
            Get
                Return pTipo
            End Get
            Set(ByVal value As EnumTipo)
                pTipo = value
            End Set
        End Property

        Public Property MsgNenhum() As String
            Get
                Return pMsgNenhum
            End Get
            Set(ByVal value As String)
                pMsgNenhum = value
            End Set
        End Property

        'TODO: Tirar isso.
        ''' <summary>
        ''' Método que copia os itens de outra DropDown
        ''' </summary>
        ''' <value></value>
        ''' <remarks></remarks>
        Public WriteOnly Property DataSourceListItem() As DropDownList
            Set(ByVal value As DropDownList)
                Me.Items.Clear()
                For Each item As ListItem In value.Items
                    Me.Items.Add(New ListItem(item.Text, item.Value))
                Next
            End Set
        End Property

        Private Sub YCDropDownList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        End Sub

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            MyBase.OnPreRender(e)

            Select Case Tipo
                Case EnumTipo.Mes
                    Me.Items.Add(New ListItem("Janeiro", 1))
                    Me.Items.Add(New ListItem("Fevereiro", 2))
                    Me.Items.Add(New ListItem("Março", 3))
                    Me.Items.Add(New ListItem("Abril", 4))
                    Me.Items.Add(New ListItem("Maio", 5))
                    Me.Items.Add(New ListItem("Junho", 6))
                    Me.Items.Add(New ListItem("Julho", 7))
                    Me.Items.Add(New ListItem("Agosto", 8))
                    Me.Items.Add(New ListItem("Setembro", 9))
                    Me.Items.Add(New ListItem("Outubro", 10))
                    Me.Items.Add(New ListItem("Novembro", 11))
                    Me.Items.Add(New ListItem("Dezembro", 12))
            End Select

            If Me.Items.Count = 0 Then _
                Me.Items.Insert(0, New ListItem(pMsgNenhum, 0))
        End Sub

    End Class

End Namespace